<?php
App::uses('AppController', 'Controller');
/**
 * Datas Controller
 *
 * @property Data $Data
 */
class DatasController extends AppController {

	public function beforeFilter(){
		parent::beforeFilter();
		$this->Auth->allow('datas_importantes');
	}
/**
 * index method
 *
 * @return void
 */
	public function index() {
		$this->paginate = array('limit' => 50);
		if(!$this->isAdmin()){
			$this->notAuth();
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			//pr($this->request->data);
			if ($this->Data->saveAll($this->request->data)) {
				$this->Session->setFlash(__('As datas foram salvas'), 'flash/bootstrap', array('class'=>'alert alert-success'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('Não foi possível salvar. Por favor, tente novamente'), 'flash/bootstrap', array('class'=>'alert alert-error'));
			}
		}
		$this->Data->recursive = 0;
		$this->set('datas', $this->paginate());
	}
	
	public function datas_importantes(){
		$this->set('datas', $this->Data->find('all'));
	}

}
